package com.codi.api.controller.h5;

import com.codi.api.security.UserUtil;
import com.codi.base.log.annotation.Loggable;
import com.codi.base.web.RequestUtils;
import com.codi.bus.core.resultModel.BaseResult;
import com.codi.bus.core.service.AssetsIncomeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by asus on 2018/5/14.
 * 收益Controller
 */
@Controller
@RestController
@RequestMapping("h5/income")
@Slf4j
public class H5IncomeQueryController {

    @Autowired
    private AssetsIncomeService assetsIncomeService;


    /**
     * 查询收益明细
     *
     * @throws Exception
     */
    @Loggable
    @GetMapping("/profit")
    @ResponseBody
    public BaseResult queryProfit(HttpServletRequest request, String fundCode, String type, Integer beginNum, Integer requestNum) throws Exception {
        // 查询基金
        Long userId = Long.valueOf(RequestUtils.getHeader(request, "userid"));
        BaseResult result = assetsIncomeService.getProfit(userId,  fundCode, type, beginNum, requestNum);

        return result;
    }

    /**
     * 查询组合收益明细
     *
     * @throws Exception
     */
    @Loggable
    @GetMapping("/portfolioProfit")
    @ResponseBody
    public BaseResult queryPortfolioProfit(HttpServletRequest request, String tradeAcco,  String type, Integer beginNum, Integer requestNum) throws Exception {
        // 查询基金
        Long userId = Long.valueOf(RequestUtils.getHeader(request, "userid"));
        BaseResult result = assetsIncomeService.getPortfolioProfit(userId, tradeAcco, type, beginNum, requestNum);

        return result;
    }


    /**
     * 累计收益 图表数据
     *
     * @throws Exception
     */
    @Loggable
    @GetMapping("/accumulate")
    @ResponseBody
    public BaseResult queryAccumulate(HttpServletRequest request, String fundCode, String type) throws Exception {
        // 查询基金
        Long userId = Long.valueOf(RequestUtils.getHeader(request, "userid"));
        BaseResult result = assetsIncomeService.getAccum(userId,  fundCode, type);

        return result;
    }

    /**
     * 查询组合 累计收益 图表
     *
     * @throws Exception
     */
    @Loggable
    @GetMapping("/portfolioAccumulate")
    @ResponseBody
    public BaseResult queryPortfoliAccumulate(HttpServletRequest request, String tradeAcco,  String type) throws Exception {
        // 查询基金
        Long userId = Long.valueOf(RequestUtils.getHeader(request, "userid"));
        BaseResult result = assetsIncomeService.getPortfolioAccum(userId, tradeAcco, type);

        return result;
    }

}
